package com.king.controller;


import com.king.common.lang.Result;
import com.king.entity.User;
import com.king.service.UserService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author KING
 * @since 2020-08-16
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 通过路径获取参数
     * /user/1, /user/2
     * @param id
     * @return
     */
    @RequiresAuthentication //需要认证通过方可访问
    @GetMapping("/{id}")
    public Result getUser(@PathVariable("id") Long id){
        return Result.success(userService.getById(id));
    }

    @PostMapping("/save")
    public Result save(@Validated @RequestBody User user){
        return Result.success(user);
    }
}
